package web.User;

import entity.UserBean;
import services.UserServiceAll;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/AddUserInfo")
public class AddUserInfo extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json");
        String uname = req.getParameter("Uname");
        String upassword = req.getParameter("Upassword");
        String email = req.getParameter("Email");
        String uphone = req.getParameter("Uphone");
        UserBean userBean = new UserBean();
        userBean.setUname(uname);
        userBean.setEmail(email);
        userBean.setUphone(uphone);
        userBean.setRname(uname);
        userBean.setUpassword(upassword);
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String formattDate = sdf.format(now);
        userBean.setUcreateDate(formattDate);
        int num = new UserServiceAll().add(userBean);
        if(num>0){
            resp.getWriter().println("新增成功");
        }else{
            resp.getWriter().println("新增失败");
        }
    }
}
